package com.hyt.it.ogt.kq.common.bm.enums.pay.nonTaxPay;

import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;

public class BsBase64Util {

    public BsBase64Util() {
    }

    public static String encodeBase64String(byte[] byteData) {
        return Base64.encodeBase64String(byteData);
    }

    public static String encodeBase64String(String stringData) {
        return encodeBase64String(stringData, CharType.UTF8);
    }

    public static String encodeBase64String(String stringData, CharType charType) {
        try {
            return Base64.encodeBase64String(stringData.getBytes(charType.value));
        } catch (UnsupportedEncodingException var3) {
            var3.printStackTrace();
            throw new IllegalAccessError("BASE64加密失败!");
        }
    }

    public static String decodeBase64String(byte[] value) {
        return decodeBase64String(value, CharType.UTF8);
    }

    public static String decodeBase64String(byte[] base64Data, CharType charType) {
        byte[] decValue = Base64.decodeBase64(base64Data);

        try {
            return new String(decValue, charType.value);
        } catch (UnsupportedEncodingException var4) {
            var4.printStackTrace();
            throw new IllegalAccessError("BASE64解密失败!");
        }
    }

    public static String decodeBase64String(String value) {
        return decodeBase64String(value, CharType.UTF8);
    }

    public static String decodeBase64String(String value, CharType charType) {
        byte[] decValue = Base64.decodeBase64(value);

        try {
            return new String(decValue, charType.value);
        } catch (UnsupportedEncodingException var4) {
            var4.printStackTrace();
            throw new IllegalAccessError("BASE64解密失败!");
        }
    }

    public static byte[] decodeBase64(String value) {
        return Base64.decodeBase64(value);
    }

    public static byte[] decodeBase64(byte[] value) {
        return Base64.decodeBase64(value);
    }

    public static String encodeBase64UrlString(String stringData, CharType charType) {
        try {
            return Base64.encodeBase64URLSafeString(stringData.getBytes(charType.value));
        } catch (UnsupportedEncodingException var3) {
            var3.printStackTrace();
            throw new IllegalAccessError("BASE64加密失败!");
        }
    }

    public static String encodeBase64UrlString(String stringData) {
        return encodeBase64UrlString(stringData, CharType.UTF8);
    }

    public static String encodeBase64UrlString(byte[] byteData) {
        return Base64.encodeBase64URLSafeString(byteData);
    }
}
